<?php

namespace app\common\model;

use think\Model;

class TradeOrder extends Model
{
    /**
     * 创建订单支付码关系
     * @param $code
     * @param $order_id
     * @return TradeOrder|null|static
     */
    static function create_relation($code, $order_id)
    {
        $t_o = self::get(["order_id" => $order_id, "code" => $code]);
        if (empty($t_o)) {
            $t_o = new self();
            $t_o->code = $code;
            $t_o->order_id = $order_id;
            $t_o->created_time = date("Y-m-d H:i:s");
            $t_o->save();
        }
        return $t_o;
    }

    /**
     * 根据订单id获取交易码
     * @param $order_id
     * @return array|false|\PDOStatement|string|Model
     */
    static function get_trade_by_order_id($order_id)
    {
        $s = new self();
        $data = $s->where('order_id',$order_id)->find();
        return $data;
    }
}
